import React, { Component, Fragment } from 'react';
// import MyCate from './MyCate'
import context from '../utils/context';

import { category_list, category_subcate } from '../utils/api'

class TabRight extends Component {
    state = {
        goodslist: []
    }
    componentDidMount() {
        context.addListener('saveId', (id) => {
            category_subcate({ id }).then((res) => {
                this.setState({
                    goodslist: res.data.subcate.subcategory
                })
            })
        })
    }
    toGoods(id){
        this.props.history.push('/index/goods/'+id);
    }
    render() {
        return (
            <div className='tabright'>
                {this.state.goodslist.map((item2, index) => {
                    return (
                        <Fragment key={index}>
                            <h3 >{item2.name}</h3>
                            <div className='list'>
                                {
                                    /* 渲染三级分类列表 */
                                    item2.subNavs.map((item3, index) => {
                                        return (
                                            <div onClick={() => { this.toGoods(item3.id) }} key={index} className="subcate">
                                                <img src={item3.pic} alt="" />
                                                <div className="name">{item3.name}</div>
                                            </div>
                                        )
                                    })
                                }
                            </div>
                        </Fragment>
                    )
                })
                }
                {/* 三级分类 */}
                {/* <MyCate></MyCate> */}
            </div>
        );
    }
}

export default TabRight;